package com.hcyy.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

import org.springframework.stereotype.Repository;

@Repository
public class SidMaker {
	public static String makeSid(){
		String[] num={
			"0","1","2","3","4","5","6","7","8","9",
			"A","B","C","D","E","F","G","H","I","J",
			"K","L","M","N","O","P","Q","R","S","T",
			"U","V","W","X","Y","Z"	
		};
		String time=new SimpleDateFormat("yyMMddHHmmssSSS").format(Calendar.getInstance().getTime());
		int year=Integer.parseInt(time.substring(0,2))-16;
		int month=Integer.parseInt(time.substring(2,4));
		int date=Integer.parseInt(time.substring(4,6));
		int hour=Integer.parseInt(time.substring(6,8));
		int min=Integer.parseInt(time.substring(8,10));
		int sec=Integer.parseInt(time.substring(10,12));
		int millis=Integer.parseInt(time.substring(12,15));
		String st="";
		st+=convert(year).substring(1);
		st+=convert(month).substring(1);
		st+=convert(date).substring(1);
		st+=convert(hour).substring(1);
		st+=convert(min);
		st+=convert(sec);
		st+=convert(millis);
		st+=num[new Random().nextInt(36)];
		return st;
	}
	
	private static String convert(int n) {
		String[] num={
				"0","1","2","3","4","5","6","7","8","9",
				"A","B","C","D","E","F","G","H","I","J",
				"K","L","M","N","O","P","Q","R","S","T",
				"U","V","W","X","Y","Z"	
			};
		/*String[] num={
				"Z","Y","X","W","V","U","T","S","R","Q",
				"P","O","N","M","L","K","J","I","H","G",
				"F","E","D","C","B","A",
				"0","1","2","3","4","5","6","7","8","9"
			};*/
		int x=n/36;
		int y=n%36;
		String s1="";
		for(int i=0;i<num.length;i++){
			if(x==i){
				s1+=num[i];
			}
		}
		for(int i=0;i<num.length;i++){
			if(y==i){
				s1+=num[i];
			}
		}
		return s1;
	}
	
	public static void main(String[] args) {
//		System.out.println(new SimpleDateFormat("yyMMddHHmmssSSS").format(Calendar.getInstance().getTime()));
//		System.out.println(SidMaker.makeSid());
		System.out.println(SidMaker.convert(10));
	}
}
